package com.coders.android.services;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.coders.android.hibernate.dto.Peticion;
import com.coders.android.spring.service.PeticionService;

@Path("android/peticion")
@Component
public class PeticionServiceREST {

	@Autowired
	PeticionService peticionService;	
		
	@Produces(MediaType.APPLICATION_JSON)
	@Path("registrar/{imeiUsuario}/{imeiTaxi}/{latitud}/{longitud}")
	@GET
	public String insertar(
			@PathParam( "imeiUsuario" ) String imeiCliente, 
			@PathParam( "imeiTaxi" ) String imeiTaxi, 
			@PathParam( "latitud" ) double latitud,
			@PathParam( "longitud" ) double longitud ) {
		
		try {
			peticionService.insertar( new Peticion(imeiCliente, imeiTaxi, latitud, longitud, 0) );
			return "OK";
			
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}
	
	@Produces(MediaType.APPLICATION_JSON)
	@Path("eliminar/{imeiUsuario}/{imeiTaxi}")
	@GET
	public String eliminar(
			@PathParam( "imeiUsuario" ) String imeiUsuario, 
			@PathParam( "imeiTaxi" ) String imeiTaxi ) {
	
		try {
			peticionService.eliminar( imeiUsuario, imeiTaxi );
			return "OK";
			
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}		
}
